#pragma once
#include "booleanType.h"
#include "CRay.h"

class IPrimitive;

class CNodeCSG
{
private:
	//the primitive stored
	IPrimitive* m_primitive;	

	//the boolean operator
	eBoolType m_boolType;

	//the children
	CNodeCSG* m_children[2];

public:
	CNodeCSG();
	CNodeCSG(IPrimitive* p, eBoolType b, CNodeCSG* child1, CNodeCSG* child2);

	~CNodeCSG();

	bool checkIntersection(const CRay& r, float& dist, CVector3f& normal)const;
	bool isInside(const CVector3f& p)const;

	void applyNullViewMatrix();

private:
	bool checkIntersectionUnion(const CRay& r, float& dist, CVector3f& normal)const;
	bool checkIntersectionInter(const CRay& r, float& dist, CVector3f& normal)const;
	bool checkIntersectionDiff(const CRay& r, float& dist, CVector3f& normal)const;
};